// javamaps
// Copyright (c) 2010 Alina Belei
package Utils.LocationFinder;

import Rendering.*;
import Rendering.Utils.*;
import Core.*;
import java.util.*;
import javax.swing.*;

public class AddressFinder extends JPanel implements ILocationFinder{

      Trie arbore_ = new Trie();
      IMapProvider provider_=null;
      HashMap<String, Street> streetMap;

      public AddressFinder(IMapProvider t){
       provider_=t;
       streetMap = new HashMap<String, Street>();
       LoadAddress();
      }

      public void LoadAddress(){
      //  IMapProvider provider_=null;
        int count = provider_.StreetCount();
        Iterator<Street> streetIt = provider_.GetStreetIterator();
         int i=1;//pt test...? in loc de ultima strada punea null
        while(streetIt.hasNext()) {
            Street street = streetIt.next();
            streetMap.put(street.Name(), street);
          try {
                arbore_.insert(street.Name(),street.Name(), street);
                
          }
          catch (Exception e) {
              System.out.println(e.toString()); }
           
               
      }
      }

      public Street FindAddress(String adr){
          return streetMap.get(adr);
      }

      public List<String> GetSuggestions(String text){
          List<String> liststr=null;
          liststr=arbore_.listsugestions(text);
          return liststr;
      }


}